/*     */ package blockbuster;
/*     */ import blockbuster.components.BedrockComponentBase;
/*     */ import blockbuster.components.IComponentEmitterInitialize;
/*     */ import blockbuster.components.IComponentEmitterUpdate;
/*     */ import blockbuster.components.IComponentParticleRender;
/*     */ import blockbuster.components.IComponentParticleUpdate;
/*     */ import blockbuster.math.Variable;
/*     */ import blockbuster.math.molang.MolangParser;
/*     */ import com.google.gson.JsonElement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import net.minecraft.util.ResourceLocation;
/*     */ 
/*     */ public class BedrockScheme {
/*  17 */   public static final ResourceLocation DEFAULT_TEXTURE = new ResourceLocation("dragoncore", "default_particles.png");
/*  18 */   public static final Gson JSON_PARSER = (new GsonBuilder())
/*  19 */     .registerTypeAdapter(BedrockScheme.class, new BedrockSchemeJsonAdapter())
/*  20 */     .create();
/*     */ 
/*     */   
/*  23 */   public String identifier = "";
/*     */ 
/*     */   
/*  26 */   public BedrockMaterial material = BedrockMaterial.OPAQUE;
/*  27 */   public ResourceLocation texture = DEFAULT_TEXTURE;
/*     */ 
/*     */   
/*  30 */   public Map<String, BedrockCurve> curves = new HashMap<>();
/*     */ 
/*     */   
/*  33 */   public List<BedrockComponentBase> components = new ArrayList<>();
/*     */   
/*     */   public List<IComponentEmitterInitialize> emitterInitializes;
/*     */   
/*     */   public List<IComponentEmitterUpdate> emitterUpdates;
/*     */   
/*     */   public List<IComponentParticleInitialize> particleInitializes;
/*     */   
/*     */   public List<IComponentParticleUpdate> particleUpdates;
/*     */   public List<IComponentParticleRender> particleRender;
/*     */   public List<IComponentParticleMorphRender> particleMorphRender;
/*     */   private boolean factory;
/*     */   public MolangParser parser;
/*     */   
/*     */   public static BedrockScheme parse(String json) {
/*  48 */     return (BedrockScheme)JSON_PARSER.fromJson(json, BedrockScheme.class);
/*     */   }
/*     */ 
/*     */   
/*     */   public static BedrockScheme parse(JsonElement json) {
/*  53 */     return (BedrockScheme)JSON_PARSER.fromJson(json, BedrockScheme.class);
/*     */   }
/*     */ 
/*     */   
/*     */   public static JsonElement toJson(BedrockScheme scheme) {
/*  58 */     return JSON_PARSER.toJsonTree(scheme);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static BedrockScheme dupe(BedrockScheme scheme) {
/*  67 */     return parse(toJson(scheme));
/*     */   }
/*     */ 
/*     */   
/*     */   public BedrockScheme() {
/*  72 */     this.parser = new MolangParser();
/*     */ 
/*     */     
/*  75 */     this.parser.register(new Variable("variable.particle_age", 0.0D));
/*  76 */     this.parser.register(new Variable("variable.particle_lifetime", 0.0D));
/*  77 */     this.parser.register(new Variable("variable.particle_random_1", 0.0D));
/*  78 */     this.parser.register(new Variable("variable.particle_random_2", 0.0D));
/*  79 */     this.parser.register(new Variable("variable.particle_random_3", 0.0D));
/*  80 */     this.parser.register(new Variable("variable.particle_random_4", 0.0D));
/*     */     
/*  82 */     this.parser.register(new Variable("variable.particle_speed.length", 0.0D));
/*  83 */     this.parser.register(new Variable("variable.particle_speed.x", 0.0D));
/*  84 */     this.parser.register(new Variable("variable.particle_speed.y", 0.0D));
/*  85 */     this.parser.register(new Variable("variable.particle_speed.z", 0.0D));
/*  86 */     this.parser.register(new Variable("variable.particle_bounces", 0.0D));
/*     */     
/*  88 */     this.parser.register(new Variable("variable.emitter_age", 0.0D));
/*  89 */     this.parser.register(new Variable("variable.emitter_lifetime", 0.0D));
/*  90 */     this.parser.register(new Variable("variable.emitter_random_1", 0.0D));
/*  91 */     this.parser.register(new Variable("variable.emitter_random_2", 0.0D));
/*  92 */     this.parser.register(new Variable("variable.emitter_random_3", 0.0D));
/*  93 */     this.parser.register(new Variable("variable.emitter_random_4", 0.0D));
/*     */     
/*  95 */     this.parser.register(new Variable("variable.heady", 0.0D));
/*  96 */     this.parser.register(new Variable("variable.bodyyaw", 0.0D));
/*  97 */     this.parser.register(new Variable("variable.headpitch", 0.0D));
/*     */   }
/*     */ 
/*     */   
/*     */   public BedrockScheme factory(boolean factory) {
/* 102 */     this.factory = factory;
/*     */     
/* 104 */     return this;
/*     */   }
/*     */ 
/*     */   
/*     */   public boolean isFactory() {
/* 109 */     return this.factory;
/*     */   }
/*     */ 
/*     */   
/*     */   public void setup() {
/* 114 */     getOrCreate(BedrockComponentInitialSpeed.class);
/*     */     
/* 116 */     this.emitterInitializes = getComponents(IComponentEmitterInitialize.class);
/* 117 */     this.emitterUpdates = getComponents(IComponentEmitterUpdate.class);
/* 118 */     this.particleInitializes = getComponents(IComponentParticleInitialize.class);
/* 119 */     this.particleUpdates = getComponents(IComponentParticleUpdate.class);
/* 120 */     this.particleRender = getComponents(IComponentParticleRender.class);
/* 121 */     this.particleMorphRender = getComponents(IComponentParticleMorphRender.class);
/*     */ 
/*     */     
/* 124 */     for (Map.Entry<String, BedrockCurve> entry : this.curves.entrySet())
/*     */     {
/* 126 */       ((BedrockCurve)entry.getValue()).variable = (Variable)this.parser.variables.get(entry.getKey());
/*     */     }
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends IComponentBase> List<T> getComponents(Class<T> clazz) {
/* 132 */     List<T> list = new ArrayList<>();
/*     */     
/* 134 */     for (BedrockComponentBase component : this.components) {
/*     */       
/* 136 */       if (clazz.isAssignableFrom(component.getClass()))
/*     */       {
/* 138 */         list.add((T)component);
/*     */       }
/*     */     } 
/*     */     
/* 142 */     if (list.size() > 1)
/*     */     {
/* 144 */       Collections.sort(list, Comparator.comparingInt(IComponentBase::getSortingIndex));
/*     */     }
/*     */     
/* 147 */     return list;
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T get(Class<T> clazz) {
/* 152 */     for (BedrockComponentBase component : this.components) {
/*     */       
/* 154 */       if (clazz.isAssignableFrom(component.getClass()))
/*     */       {
/* 156 */         return (T)component;
/*     */       }
/*     */     } 
/*     */     
/* 160 */     return null;
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T getExact(Class<T> clazz) {
/* 165 */     for (BedrockComponentBase component : this.components) {
/*     */       
/* 167 */       if (clazz.equals(component.getClass()))
/*     */       {
/* 169 */         return (T)component;
/*     */       }
/*     */     } 
/*     */     
/* 173 */     return null;
/*     */   }
/*     */   
/*     */   public <T extends BedrockComponentBase> T add(Class<T> clazz) {
/*     */     BedrockComponentBase bedrockComponentBase;
/* 178 */     T result = null;
/*     */ 
/*     */     
/*     */     try {
/* 182 */       bedrockComponentBase = clazz.getConstructor(new Class[0]).newInstance(new Object[0]);
/*     */       
/* 184 */       this.components.add(bedrockComponentBase);
/* 185 */       setup();
/*     */     }
/* 187 */     catch (Exception exception) {}
/*     */ 
/*     */     
/* 190 */     return (T)bedrockComponentBase;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T getOrCreate(Class<T> clazz) {
/* 201 */     return getOrCreate(clazz, clazz);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T getOrCreateExact(Class<T> clazz) {
/* 212 */     return getOrCreateExact(clazz, clazz);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T getOrCreate(Class<T> clazz, Class<T> subclass) {
/* 224 */     T result = get(clazz);
/*     */     
/* 226 */     if (result == null)
/*     */     {
/* 228 */       result = add(subclass);
/*     */     }
/*     */     
/* 231 */     return result;
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T getOrCreateExact(Class<T> clazz, Class<T> subclass) {
/* 236 */     T result = getExact(clazz);
/*     */     
/* 238 */     if (result == null)
/*     */     {
/* 240 */       result = add(subclass);
/*     */     }
/*     */     
/* 243 */     return result;
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T remove(Class<T> clazz) {
/* 248 */     Iterator<BedrockComponentBase> it = this.components.iterator();
/*     */     
/* 250 */     while (it.hasNext()) {
/*     */       
/* 252 */       BedrockComponentBase component = it.next();
/*     */       
/* 254 */       if (clazz.isAssignableFrom(component.getClass())) {
/*     */         
/* 256 */         it.remove();
/*     */         
/* 258 */         return (T)component;
/*     */       } 
/*     */     } 
/*     */     
/* 262 */     return null;
/*     */   }
/*     */ 
/*     */   
/*     */   public <T extends BedrockComponentBase> T replace(Class<T> clazz, Class<T> subclass) {
/* 267 */     remove(clazz);
/*     */     
/* 269 */     return add(subclass);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void updateCurves() {
/* 277 */     for (BedrockCurve curve : this.curves.values()) {
/*     */       
/* 279 */       if (curve.variable != null)
/*     */       {
/* 281 */         curve.variable.set(curve.compute());
/*     */       }
/*     */     } 
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\BedrockScheme.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */